﻿using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using Sunny.UI;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace CoreShop.App
{
    public partial class UIDishItemList : UIUserControl
    {
        public UIDishItemList()
        {
            InitializeComponent();
            Info = new DishItemInfo();
            Text = Info.Name;
        }

        public DishItemInfo Info { get; }
        public UIDishItemList(DishItemInfo info)
        {
            InitializeComponent();
            if (info == null) throw new NullReferenceException("info");
            Info = info;
            Text = info.Name;
        }

        public string TextName
        {
            get => Text;
            set
            {
                Text = value;
                Invalidate();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (Info == null) return;
            int Added =  0;

            RectangleF descRect = new RectangleF();
            using (Font font = new Font("微软雅黑", 12f))
            {
                descRect.Location = new Point(Added + 10, 8);                
                descRect.Size = new Size(145, 50);
                e.Graphics.DrawString(Text, font, Brushes.Black, descRect);
            }

            SizeF textSize = new SizeF();
            using (Font font = new Font("微软雅黑", 10f))
            {
                e.Graphics.DrawString(Info.Money, font, Color.Chocolate, Added + 8, 55);
                textSize = e.Graphics.MeasureString(Info.Money, font);                
            }            
        }
    }
}